import urllib.request
import json
#验证账号密码
class GetToke:
    def __init__(self) -> None:
        pass
    def GetgameToke(UserName,Userpassword):
        data = {
            "agent": {
                "name": "Minecraft",
                "version": 1,
                "username": UserName,
                "password": Userpassword,
                "clientToken": "mmpmmpmmpmmpmmpmmpmmpmmp"
                }
            }
        url = 'https://authserver.mojang.com/authenticate'    
        res = requests.post(url=url,data=json.dumps(data))
        access = json.load(res)
        def GetaccessToke():
            return access['accessToken']
        def PlayerUuid():
            return access['availableProfiles']['id']

        #检验令牌有效性
        def Verification_Token(accessToken):
            Verification_Token_Data = {
                                    "accessToken": accessToken,
                                    "clientToken": "mmpmmpmmpmmpmmpmmpmmpmmp"
                                    } 
            Verification_Token_Url = 'https://authserver.mojang.com/validate'
            Verification_Token_Res = requests.post(Verification_Token_Url=url,data=json.dumps(Verification_Token_Data))
            if Verification_Token_Res == '403 Forbidden':
                print("令牌已失效")

